/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson6;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Reader;

/**
 *
 * @author netcracker
 */
public class Lesson6 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
       

        Vectors.setVectorFactory(new LinkedListVectorFactory());
        LinkedListVector av = (LinkedListVector) Vectors.createInstance(5);
        System.out.println(av.toString());
        Vectors.setVectorFactory(new ArrayVectorFactory());
        ArrayVector llv = (ArrayVector) Vectors.randVector(10);
        System.out.println(llv.toString());
        
        
        OutputStream os = new FileOutputStream("obj.txt");
        InputStream is = new FileInputStream("obj.txt");
        DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream("out.bin"));
        DataInputStream dataInputStream = new DataInputStream(new FileInputStream("out.bin"));
        Vectors v = new Vectors();
        //Vector<Byte> vctb = new Vector<Byte>();

        for (int i = 0; i < 20; i++) {
            llv.add(i);
        }

        v.outputVector(llv, dataOutputStream);
        IVector vcto = v.inputVector(dataInputStream);
        
        System.out.println("DataStreams");
        System.out.println(vcto.toString());
//////////////////


        System.out.println("WRITING");
        FileWriter w = new FileWriter("wobj.txt");
        v.writeVector(vcto, w);
        v.writeVector(llv, w);



        /////////////////
        ObjectOutputStream oos = new ObjectOutputStream(os);
        double[] d = {123.0, 41.0, 3.0};
        LinkedListVector arrayVector = new LinkedListVector();
        arrayVector.fill(d);
        oos.writeObject(arrayVector);
        ObjectInputStream is2 = new ObjectInputStream(is);
        LinkedListVector avv = (LinkedListVector) is2.readObject();
        System.out.println(avv.toString());

        /////////////////////
        System.out.println("READING");
        Reader r = new FileReader("wobj.txt");

        IVector v1 =  v.readVector(r);
        IVector v2 =  v.readVector(r);


        for (int i = 0; i < v1.getLength(); i++) {
            System.out.println(v1.get(i));
        }

        System.out.println("================");
        
        for (int i = 0; i < v2.getLength(); i++) {
            System.out.println(v2.get(i));
        }
        
        System.out.println("Finish!");
        
    }
}
